package crivia.ecp.carry.html.form;

import crivia.ecp.carry.html.DO;
import crivia.ecp.common.ECR;
import crivia.ecp.exception.WrongDocumentObject;
import crivia.ecp.i.DI;
/**
 * Abstract Form DataArea.<br/>
 * Key & Value.<br/>
 */
public abstract class DataArea extends DO implements DI {

	public DataArea() {
		super();
	}
	
	public DataArea(String key, String value) {
		super();
		if (! ECR.hasCondition(key)){
			throw new WrongDocumentObject("No Key.");
		}
		this.key = key;
		this.value = ECR.ns(value);
	}
	
	protected String key;
	public String getKey() {
		return key;
	}
	public DataArea setKey(String key) {
		this.key = key;
		return this;
	}
	
	protected String scriptKey;
	public String getScriptKey() {
		if (!ECR.hasCondition(scriptKey)){
			scriptKey = key;
		}
		return scriptKey;
	}
	public DataArea setScriptKey(String scriptKey) {
		this.scriptKey = scriptKey;
		return this;
	}
	
	
	protected String value = "";
	public String getValue() {
		return value;
	}
	public DataArea setValue(String value) {
		this.value = ECR.ns(value);
		return this;
	}
	
	protected void beforeToString(){}
	
	@Override
	public String toString() {
		addAttr("id", getScriptKey());
		addAttr("name", getKey());
		addAttr("value", getValue());
		beforeToString();
		return super.toString();
	}

}
